<template>
    <div>
        <Modal v-model="modal.delivery" title="确认发货" :mask-closable="false" @on-visible-change="changeModalVisibleResetForm('editForm', $event)" width="1020">
            <Form ref="editForm" :model="form" :label-width="120" :rules="validateRules">
              <Row>
                <i-col span="12">
                <FormItem label="物流公司名称" prop="logisticsCompany">
                <!-- <Input v-model="form.logisticsCompany" placeholder="请输入物流公司名称" clearable/> -->
                <Select v-model="form.logisticsCode" filterable placeholder="请选择物流公司名称" :label-in-value="true" @on-change="changeLogistics">
                  <i-option
                    v-for="item in logisticsData"
                    :value="item.code"
                    :key="item.code"
                  >{{item.companyname}}</i-option>
                </Select>
              </FormItem>
                </i-col><i-col span="12">
                <FormItem label="物流公司编码" prop="logisticsCode">
                <Input v-model="form.logisticsCode" placeholder="请输入物流公司编码" readonly/>
              </FormItem>
                </i-col>
              </Row>
              <Row>
                <i-col span="12">
                <FormItem label="物流单号" prop="logisticsNo">
                <Input v-model="form.logisticsNo" placeholder="请输入物流单号" clearable/>
              </FormItem>
                </i-col>
              </Row>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="resetFormCancelModal('editForm', 'delivery')">取消</Button>
                <Button type="primary" size="large" @click="deliveryGoods" :loading="loading.edit">发货</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import logistics from '@/api/kuaidi100_companys.json'
    import {
      isDeliverySelect
    } from '@/api/select.js'
    export default {
        name: 'GoodsOrderLogisticsDeliver',
        data() {
            return {
                logisticsData: logistics,
                isDeliverySelect: isDeliverySelect,
                modal: {
                    add: false,
                    edit: false,
                    delivery: false
                },
                loading: {
                    add: false,
                    edit: false
                },
                form: {
                    shopId: null,
realName: null,
phone: null,
province: null,
city: null,
district: null,
addressAlias: null,
address: null,
area: null,
isDeliver: null,
logisticsCompany: null,
logisticsCode: null,
logisticsNo: null,

                },
                validateRules: {
                    shopId: [
{type: 'integer', required: true, message: '此项为必须项', trigger: 'blur, change'}
],
realName: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
phone: [
{type: 'string', required: true, message: '此项为必须项', trigger: 'blur'},
{type: 'string', min: 1, max: 11, message: '必须1-11个字符', trigger: 'blur'}
],
province: [
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
city: [
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
district: [
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
addressAlias: [
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
address: [
{type: 'string', min: 1, max: 255, message: '必须1-255个字符', trigger: 'blur'}
],
area: [
{type: 'string', min: 1, max: 50, message: '必须1-50个字符', trigger: 'blur'}
],
logisticsCompany: [
{type: 'string', min: 1, max: 255, message: '必须1-255个字符', trigger: 'blur'}
],
logisticsCode: [
{type: 'string', min: 1, max: 20, message: '必须1-20个字符', trigger: 'blur'}
],
logisticsNo: [
{type: 'string', min: 1, max: 32, message: '必须1-32个字符', trigger: 'blur'}
],

                }
            }
        },
        computed: {},
        mounted() {},
        methods: {
          changeModalVisibleResetForm(formRef, visible) {
                if (!visible) {
                    this.$refs[formRef].resetFields()
                }
            },
            resetFormCancelModal(formRef, modal) {
                this.modal[modal] = false
                this.$refs[formRef].resetFields()
            },
            /**
             * 发货
             */
            deliveryGoods() {
              this.$emit('deliveryGoods', this.form)
            },
            /**
             * 选择物流公司
             */
            changeLogistics(val) {
              if (val && val.label) {
                this.form.logisticsCompany = val.label
                if (this.form.logisticsCompany === '同城配送') {
                  this.form.logisticsNo = '无'
                }
              }
            }
        }
    }
</script>

<style>
</style>
